// request 基本封装
import axios from 'axios'

// interface IResponse {
//     message: string,
//     result: [],
//     success: boolean
// }
// result 不能直接定义类型
interface IResponse<T> {
    message: string,
    result: T,
    success: boolean
}
type IParams = {
    url: string,
    type: 'get' | 'post',
    data?: any
}

function request(data: IParams): Promise<IResponse<number[]>>{
    return new Promise((resolve, reject)=>{
        setTimeout(()=>{
            resolve({
                message: '获取数据成功',
                result: [1, 2, 3],
                success: true
            })
        }, 2000)
    })
}

const get = (url: string, data: any)=>{
    return axios.get(url, data);
}

const post = (url: string, data: any)=>{
    return axios.post(url, data);
}

export {
    request,
    get,
    post
}